/**
 * Created by zhouwei on 2017/4/13.
 */
import config from '../config/index'

export default {
    localStorage (key, val) {
        if (val === undefined) return window.JSON.parse(window.localStorage.getItem(key))
        if (!val) return window.localStorage.removeItem(key)
        window.localStorage.setItem(key, window.JSON.stringify(val))
    },
    timeStampWithCache(key){
        /*时间戳判断数据是否缓存*/
        let currentLoginTime = parseInt(new Date().getTime() / 1000);
        let lastLoginTime = this.localStorage("loginTime");
        if (currentLoginTime-lastLoginTime < config.cacheTime.time) return;
        window.localStorage.removeItem(key);
    }
}
